<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>新闻发布</title>
    <link rel="stylesheet" type="text/css" href="./../jquery-easyui-1.6.6/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="./../jquery-easyui-1.6.6/themes/icon.css">
    <script type="text/javascript" src="./../jquery-easyui-1.6.6/jquery.min.js"></script>
    <script type="text/javascript" src="./../jquery-easyui-1.6.6/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="./../js/jquery.serializejson.min.js"></script>
    <script type="text/javascript" src="../js/xheditor-1.2.2/jquery/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="../js/xheditor-1.2.2/xheditor-1.2.2.min.js"></script>
    <script type="text/javascript" src="../js/xheditor-1.2.2/xheditor_lang/zh-cn.js"></script>
    <style>
        .title {
            width: 400px;
        }
    </style>
    <script>
        var timestamp = new Date().getTime();
    </script>
</head>

<body>
    <input id="dd" type="text" class="easyui-datebox" required="required">
    <div id="dlg" class="easyui-dialog" title="Basic Dialog" data-options="iconCls:'icon-save'" style="width:400px;height:200px;padding:10px">
        <form id="ff" method="post">

            <div style="margin-bottom:20px">
                <input class="easyui-textbox title" name="标题" data-options="label:'新闻标题:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox classes" name="类别" label="新闻类别:"><option value="cs">国内新闻</option><option value="cs">国际新闻</option></select>
            </div>
            新闻属性: <input type="checkbox" name="leibei" class="shuxing"> 头条 <input type="checkbox" value="" name="leibei"> 热点
            <br> 新闻内容:
            <textarea cols="120" rows="30" name="content" class="xheditor details" style="margin-top:30px"></textarea>
        </form>
        <div style="text-align:center;padding:5px 0">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">Submit</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">清空</a>
        </div>
    </div>
    <script>
        function submitForm() {
            $('#ff').form('submit', {
                onSubmit: function() {
                    if ($(this).form('enableValidation').form('validate')) {

                        var formData = $('#ff').serializeJSON();
                        if (formData._id.length > 0) {
                            $.ajax({
                                url: `${parent.globalUrl}news/data/` + formData._id,
                                type: 'put',
                                data: formData
                            }).then(res => {
                                // console.log(res);
                                $('#dlg').dialog('close'); //关闭窗口
                                $('#dg').datagrid('reload'); //刷新页面
                            })
                        } else {
                            delete formData._id;
                            $.ajax({
                                url: `${parent.globalUrl}news/data/`,
                                type: 'post',
                                data: formData
                            }).then(res => {
                                // console.log(res);
                                $('#dlg').dialog('close'); //关闭窗口
                                $('#dg').datagrid('reload'); //刷新页面
                            })
                        }
                    }
                    return false;
                }
            });
        }
    </script>
</body>

</html>